tree algorithms